package net.ojbk.timeSpace.timeAxis.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import net.ojbk.timeSpace.timeAxis.beans.Img;
import net.ojbk.timeSpace.timeAxis.beans.Msg;
import net.ojbk.timeSpace.timeAxis.beans.TimeBlade;
import net.ojbk.timeSpace.timeAxis.dao.MsgDao;
import net.ojbk.timeSpace.timeAxis.dao.TimeBladeDao;
import net.ojbk.timeSpace.timeAxis.dao.ImgDao;
import net.ojbk.timeSpace.timeAxis.service.IBladeService;

@Service("bladeServer")
public class BladeServiceImpl implements IBladeService {
	@Autowired
	@Qualifier("MsgDao")
	private MsgDao msgDao;
	
	@Autowired
	@Qualifier("TimeBladeDao")
	private TimeBladeDao timeBladeDao;
	
	@Autowired
	@Qualifier("ImgDao")
	private ImgDao ImgDao;
	
	@Override
	public TimeBlade getBladeInfo(int bladeId) {
		// TODO Auto-generated method stub
		return timeBladeDao.selectOneRecord(bladeId);
	}

	@Override
	public List<Msg> getAllMsgByBladeId(int bladeId) {
		// TODO Auto-generated method stub
		return msgDao.queryAllRecordByTimeBladeId(bladeId);
	}

	@Override
	public List<String> getAllImgByBladeId(int bladeId) {
		// TODO Auto-generated method stub
		List<Img> imgList = ImgDao.selectAllRecordByTimeBladeId(bladeId);
		List<String> UUIDList = new ArrayList<>();
		for (Img eachImg : imgList) {
			UUIDList.add(eachImg.getImgUUID());
		}
		return UUIDList;
	}

	@Override
	public void pushMsg(Msg newMsg) {
		// TODO Auto-generated method stub
		msgDao.addOneRecord(newMsg);
	}

	@Override
	public void modifMsgConfig(TimeBlade blade, boolean newConfig) {
		// TODO Auto-generated method stub
		blade.setMsgConfig(newConfig);
		timeBladeDao.updateOneRecord(blade);
	}

}
